package com.piece.core.web.authority.store;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * 认证服务器使用数据库存取令牌
 */
@Configuration
@ConditionalOnProperty(prefix = "spring.security.token", name = "store-type", havingValue = "db")
public class AuthDbTokenStore {

    @Resource
    private DataSource dataSource;

    @Bean
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }
}
